﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.IO;
using nc = functionService.nameCod ;
using h = functionService.shorts;
using da = functionService.DATECOD;
using fr = HK.FiscalRegistrar.FiscalRegistrar;
using vv = functionService.serfun_city7;
using tgw = functionService.tagWork;
using HK.Reports;


namespace ETALON
{
    class ClassFormDocZ
    {
        const int i_NKP = 1, i_SFP = 2, i_SFR = 3, i_NKR = 4;
        public functionService.prm_city q; public raw.modeWAED currentModeWAED;
        public REPORTS.PRINT prnt; public raw.typeDoc currentTypeDoc; public raw.typeDocOP  currentTypeDocOP;
        public DataTable rd, td, rdDod;
        public const string sirRdZ = "sir_rd_z", sirTdZ = "sir_td_z", shema = "city";
        Tool tool;
        public string CODt;

        public ClassFormDocZ(Tool toolOut)
        {
            tool = toolOut; InitializeComponentMy();
        }
        public ClassFormDocZ(int indexDoc, Tool toolOut) 
        {
            tool = toolOut; InitializeComponentMy(); selectOnIndex(indexDoc); setModeWAED(ETALON.raw.modeWAED.loadForReadOnly);
        }


        private void InitializeComponentMy()
        {
            vv.codKol.bKnowCod = false; CODt = "0"; vv.codKol.enterEnter = false;
            rd = new DataTable(); td = new DataTable();
            q = new functionService.prm_city();
            q.con.pass = q.tk(param.pass_inServ_55); q.con.co(q.tk(param.server_1));
            tool.toolStripStatusLabel1.Text = q.tk(param.server_1);
            string sprset = q.tk((int)param.pr_tov_inNk2_question_51);//0-no,1-yes
            tool.toolStripMenuItem1.Checked = fatr(sprset);

            vv.rz.enterCodTrue = false;

            currentModeWAED = ETALON.raw.modeWAED.load; currentTypeDocOP = ETALON.raw.typeDocOP.no;
            setModeTypeDoc(ETALON.raw.typeDoc.NKP);
            
            prnt = new ETALON.REPORTS.PRINT();
            
            

            loadDoc();
        }

        public bool true_false(int i1i0) { bool b = false; if (i1i0 == 0) { b = false; } else if (i1i0 == 1) { b = true; } return b; }
        public bool fatr(string s1s0) { bool b = false; if (s1s0 == "0") { b = false; } else if (s1s0 == "1") { b = true; } return b; }
        public void editSir(object kol, object kol2)
        {
            ////try
            ////{
            ////q.UpdateData(sql_SAED.DEL_plase(q.tk_int(param.zakaz_current_13), q.tk_int(param.zakaz_plase_current_15)));
            ////listView1.SelectedItems[0].Remove();
            //object oo = q.tk_readTagTd(param.sir_td_tag_29, 
            //    ETALON.raw.typeTagTd.cod123_5); //h.m(oo);
            //q.UpdateData(sql_doc_z.edit_td(oo, kol,kol2));
            ////tool.listView2.SelectedItems[0].Remove();

            //loadDocTd();

            //setModeWAED(raw.modeWAED.load );
            ////}
            ////catch { }
        }
        public void deleteSir()
        {
            //try
            //{
            //q.UpdateData(sql_SAED.DEL_plase(q.tk_int(param.zakaz_current_13), q.tk_int(param.zakaz_plase_current_15)));
            //listView1.SelectedItems[0].Remove();
            object oo = q.tk_readTagTd(param.sir_td_tag_29, ETALON.raw.typeTagTd.cod123_5); //h.m(oo);
            q.UpdateData(sql_doc_z.DEL_td(oo));
            tool.listView2.SelectedItems[0].Remove();

            loadDocTd();

            setModeWAED(raw.modeWAED.delTd);
            //}
            //catch { }
        }
        public void selectSir()
        {
            try
            {
                q.put(param.sir_td_tag_29, tool.listView2.SelectedItems[0].Tag);
                setModeWAED(raw.modeWAED.afterSelectTd);
            }
            catch { }
        }
        public void IsHereDoc(int coddo)
        {
               
        }
        public void setCodEnter(bool enterCodTrueOut)
        {
            vv.rz.enterCodTrue = enterCodTrueOut;
        }

        public void selectOnIndex(int indxo)
        {
            tool.listView3.Items[indxo].Selected = true;

            string stext = tool.listView3.Items[indxo].Text;
            string stag = tool.listView3.Items[indxo].Tag.ToString();

            string stag_doc = functionService.tagWork.readTAG(stag, (int)raw.typeTagRd.codd001_0);
            q.put(param.sir_current_doc_20, stag_doc);
            string stag_doc_cod123 = functionService.tagWork.readTAG(stag, (int)raw.typeTagRd.cod123_3);
            q.put(param.sir_current_doc_cod123_21, stag_doc_cod123);
            q.put(param.sir_tag_rd_24, stag);
            // fs.shorts.m(stext);
            setStatus(stext); loadDocTd();
            setModeWAED(ETALON.raw.modeWAED.afterSelectRd);

        }
        public void loadDocTd()
        {

            tool.listView2.Items.Clear();
           
            object iCodd = q.tk_readTagRd(param.sir_tag_rd_24, ETALON.raw.typeTagRd.codd_5);
            // h.m(22);
            //--------------------------------------
            td = q.selectAny(sql_doc_z.td(iCodd));
            //--------------------------------------
            //q.sh(td);
            // h.m(23);
            object osd = q.selectScalar(sql_doc_z.td_sum(iCodd));
            tool.listView2.Columns[4].Text = functionService.shorts.a("Сумма:", osd);
            ListViewItem lvi; ListViewItem.ListViewSubItem lvis; 
            foreach (DataRow r in td.Rows)
            {
                lvi = new ListViewItem();
                lvi.Text = r[0].ToString(); //r[0] - name

                lvis = new ListViewItem.ListViewSubItem();
                lvis.Text = r[1].ToString(); //kol1
                lvi.SubItems.Add(lvis);

                lvis = new ListViewItem.ListViewSubItem();
                lvis.Text = r[2].ToString(); //kol2
                lvi.SubItems.Add(lvis);


                lvis = new ListViewItem.ListViewSubItem();
                lvis.Text = r[3].ToString();//pr
                lvi.SubItems.Add(lvis);

                lvis = new ListViewItem.ListViewSubItem();
                lvis.Text = r[4].ToString();//sd
                lvi.SubItems.Add(lvis);

                lvis = new ListViewItem.ListViewSubItem();
                lvis.Text = r[6].ToString();//123
                lvi.SubItems.Add(lvis);

                //r[0]-name, r[1]-kol, r[2]-kol2 , r[3]-pr, r[5]-codd, r[6]-cod123 
                lvi.Tag = functionService.shorts.az(r[0], r[1], r[2], r[3], r[5], r[6]);
                lvi.ImageIndex = 2;
                tool.listView2.Items.Add(lvi);
            }
        }
        public void loadDoc()
        {

            tool.listView3.Items.Clear();
            /*
             * SELECT right(codd,3)*1 as codd3, s.nd,name_cod(n.name, s.codo) as codo, s.cod123, s.dd, s.codd
                FROM sir_rd s
                left join sir_listorg n on s.codo = n.cod
                where
                (1*mid(codd,6,1)=typeDoc)
                and
                (left(codd,5)*1 = coddDate_1year_09month_13day_10913) order by codd;
             * 
             */
            string sdd = q.tk(param.day_work_7);
            rd = q.selectAny(sql_doc_z.rdDocType((int)currentTypeDoc, da.codDATE_10913_from_DATETIME(sdd)));
            ListViewItem lvi;
            foreach (DataRow r in rd.Rows)
            {
                lvi = new ListViewItem();
                lvi.Text = functionService.shorts.a("№", r[0], "/", r[1], " ", functionService.DATECOD.cod_to_date(r[4]), " ", r[2]); //r[3] - cod123 r[4] - coddate
                // enum typeTagTd { name_0 = 0, kol_1 = 1, kol2_2 = 2, pr_3 = 3, codd_5 = 5, cod123_6 = 6 }
                // enum typeTagRd { codd001_0=0, cod123_1=1, dd_2=2, corg_3=3, nd_4=4, codd_5=5 }
                lvi.Tag = functionService.shorts.az(r[0], r[1], r[2], r[3], r[4], r[5]);


                //r[0]-name, r[1]-kol, r[2]-kol2 , r[3]-pr, r[5]-codd, r[6]-cod123 
                // lvi.Tag = functionService.shorts.az(r[0], r[1], r[2], r[3], r[5], r[6]);


                lvi.ImageIndex = 10;
                tool.listView3.Items.Add(lvi);
            }
            setModeWAED(ETALON.raw.modeWAED.load);
        }
        public void loadDoc(raw.typeDocOP dop)
        {

            tool.listView3.Items.Clear();
            string sdd = q.tk(param.day_work_7);
            if(dop == ETALON.raw.typeDocOP.no)
            {
                rd = q.selectAny(sql_doc_z.rdDocType((int)currentTypeDoc, da.codDATE_10913_from_DATETIME(sdd)));
            }
            else 
            {
              //  h.m(h.aa((int)currentTypeDoc, "=(int)currentTypeDoc", (int)dop, "=(int)dop ", da.codDATE_10913_from_DATETIME(sdd), "=da.codDATE_10913_from_DATETIME(sdd)  "));
                rd = q.selectAny(sql_doc_z.rdDocType((int)currentTypeDoc, (int)dop, da.codDATE_10913_from_DATETIME(sdd)));
            }
            ListViewItem lvi;
            foreach (DataRow r in rd.Rows)
            {
                lvi = new ListViewItem();
                lvi.Text = functionService.shorts.a("№", r[0], "/", r[1], " ", functionService.DATECOD.cod_to_date(r[4]), " ", r[2]); //r[3] - cod123 r[4] - coddate
                lvi.Tag = functionService.shorts.az(r[0], r[1], r[2], r[3], r[4], r[5]);

                lvi.ImageIndex = 10;
                tool.listView3.Items.Add(lvi);
            }
            setModeWAED(ETALON.raw.modeWAED.load);
        }
        public int findInListView(string scoddo)
        {
            int ic = tool.listView3.Items.Count; string codd_tag5 = ""; int ifi = 0;
            for (int i = 0; i < ic; i++)
            {
                codd_tag5 = functionService.tagWork.readTAG(tool.listView3.Items[i].Tag.ToString(), 5);
                if (codd_tag5 == scoddo) { ifi = i; break; }
            }
            return ifi;
        }

        public bool true1_False0(object  i01)
        {
            if (i01.ToString() == "1") { return true; } else return false; 
        }
        public void addDocTd_SkladNk2()
        {
            string s = "", pr = "0", kol = "", kol2 = "";
           // h.m(vv.list_sourse);
            //vv.list_sourse = funSetListSourse(currentTypeDoc); //h.m(vv.list_sourse);
            listAnyEdit f; object oves;
            bool bProdZeha = false ;
          //  h.m(vv.list_sourse);
            if (vv.list_sourse == "list_sc")
            {
                f = new listAnyEdit("city", vv.list_sourse, "cod<3000"); bProdZeha=true1_False0(q.tk(param.bProdZeha_61));
            }
            else 
            {
                f = new listAnyEdit("city", "list_tehsir_z", "cod<3000"); 
            }
            FormKolZakaz fkk;
            city7.FormCodKol k;
            if (vv.codKol.bKnowCod)
            {
                k = new city7.FormCodKol(); 
                k.ShowDialog();
                kol2 = "1"; 
                kol = k.KOL; 
                CODt = k.COD;
                
                //k = new ETALON.WORK.FormTXT(); kol = "1";
                //k.textBox1.Text = "КОД"; k.textBox1.SelectAll();
                //k.ShowDialog(); CODt = k.txtEnter;
                //k.textBox1.Text = "КОЛИЧЕСТВО"; k.textBox1.SelectAll();
                //k.ShowDialog();  kol2 = k.txtEnter;

            }
            else
            {
                f.ShowDialog(); CODt = f.sCod;
            }

            if (Convert.ToInt32(CODt) > 0)
            { oves = q.selectScalar(string.Concat("select ves from list_sc where cod =", CODt  ,";")); }
            else
            { oves = 1; }
             string s51 = q.tk((int)param.pr_tov_inNk2_question_51);

            if (fatr(s51))
            {
                FormKolZakaz fk = new FormKolZakaz("Введите ЦЕНУ"); 
                fk.ShowDialog(); if (fk.IsSelect) { pr = fk.valueEnter; }
            }

            if (bProdZeha == false) 
            {
                 fkk = new FormKolZakaz("Введите КОЛИЧЕСТВО", "1");
                if (currentTypeDocOP != ETALON.raw.typeDocOP.ost)
                {
                    fkk.ShowDialog(); if (fkk.IsSelect) { kol = fkk.valueEnter; } else { kol = "1"; }
                }
                else
                {
                    kol = "1";
                }
            }
            else
            {
                kol = oves.ToString();
            }
            FormKolZakaz f2 = new FormKolZakaz("Введите КОЛИЧЕСТВО 2");
            if (vv.codKol.bKnowCod == false )
            {
                f2.ShowDialog(); kol2 = f2.valueEnter; //kol = "1";
            }

            object ocod123 = q.selectScalar(string.Concat("select max(cod123)+1 as cod123 from ", sirTdZ, ";"));

            if (vv.codKol.bKnowCod == false)
            {
                if (f.IsOK && f2.IsSelect)
                {

                    kol2 = f2.valueEnter;
                    pr = q.tk((int)param.pr_tov_inNk2_sklad_50);// fk.valueEnter;
                    s = sql_doc_z.ADD_td(ocod123, CODt, pr, kol, kol2, q.tk_readTagRd(param.sir_tag_rd_24, ETALON.raw.typeTagRd.codd_5));
                    q.UpdateData(s);
                }
            }
            else 
            {
                pr = q.tk((int)param.pr_tov_inNk2_sklad_50);
                s = sql_doc_z.ADD_td(ocod123, CODt, pr, kol, kol2, q.tk_readTagRd(param.sir_tag_rd_24, ETALON.raw.typeTagRd.codd_5));
                q.UpdateData(s);
            }
              
            setModeWAED(ETALON.raw.modeWAED.addTd);
            loadDocTd();
            if (vv.codKol.enterEnter)
            {
                addDocTd_SkladNk2();
            }
        }
        
        public void addDocTd()
        {
            string s = "", pr = "", kol = "0", kol2 = "0";

            listAnyEdit f = new listAnyEdit("city", vv.list_sourse, true); f.ShowDialog();
            
            if(vv.filter.IsSave) q.put(62, vv.filter.tag);



            FormKolZakaz fkk; FormKolZakaz f2;
            if (f.IsOK)// if (f.IsOK && fk.IsSelect && fkk.IsSelect)
            {
                vv.editTd.name_cod = f.sText; vv.editTd.ct = f.sCod;
                if (vv.list_sourse == "list_sc")
                {
                    vv.editTd.ves = q.selectScalar
                            (
                            string.Concat
                            (
                            "select ves from list_sc where cod = ", vv.editTd.ct, ";"
                            )
                            );
                }
                else vv.editTd.ves = 1;
                fkk = new FormKolZakaz("Введите КОЛИЧЕСТВО","0"); fkk.ShowDialog();
                f2 = new FormKolZakaz("Введите КОЛИЧЕСТВО 2", vv.editTd.ves.ToString()); f2.ShowDialog();
                if (fkk.IsSelect && f2.IsSelect)// if (f.IsOK && fk.IsSelect && fkk.IsSelect)
                {
                    object ocod123 = q.selectScalar(string.Concat("select max(cod123)+1 as cod123 from ", sirTdZ, ";"));
                    kol = fkk.valueEnter;
                    kol2 = f2.valueEnter;
                    pr = "0";
                    s = sql_doc_z.ADD_td(ocod123, f.sCod, pr, kol, kol2, q.tk_readTagRd(param.sir_tag_rd_24, ETALON.raw.typeTagRd.codd_5));
                    q.UpdateData(s);
                }
                setModeWAED(ETALON.raw.modeWAED.addTd);
                loadDocTd();
            }
            
            
        }
        public void addDoc(int corgo)
        {
            string sdd = q.tk(param.day_work_7);
            int icd = da.codDATE_10913_from_DATETIME(sdd);

            string sqlCOUNT = string.Concat
                                (
                                "SELECT COUNT(codd) as codd FROM ", sirRdZ, 
                                " WHERE 1*left(codd,5) = '", icd, 
                                "' And 1*right(left(codd,6),1) = ", (int)currentTypeDoc, ";"
                                );
            if (currentTypeDocOP == ETALON.raw.typeDocOP.ost)
            {
                sqlCOUNT = string.Concat
                               (
                               "SELECT COUNT(codd) as codd FROM ", sirRdZ, 
                               " WHERE 1*left(codd,5) = '", icd,
                               "' And 1*right(codd,4) = 1900;"
                               );
            }
            else if (currentTypeDocOP == ETALON.raw.typeDocOP.prihSklad)
            {
                sqlCOUNT = string.Concat
                                (
                                "SELECT COUNT(codd) as codd FROM ", sirRdZ,
                                " WHERE 1*left(codd,5) = '", icd,
                                "' And 1*left(right(codd,4),2) = 17;"
                                );
            }
            


            object occ = q.selectScalar(sqlCOUNT);
            //h.m(occ);
            int ic = 0, icc = 1000 + ic; string iccs = ""; //fs.shorts.m(ic);
            string sicd = string.Concat(icd, (int)currentTypeDoc, "001");

            if (currentTypeDocOP == ETALON.raw.typeDocOP.ost) { sicd = string.Concat(icd, "1900"); }
            else if (currentTypeDocOP == ETALON.raw.typeDocOP.prihSklad) { sicd = string.Concat(icd,"1301"); }

            int icodd = 0;


            if (Convert.ToInt32(occ) > 0)
            {
                rdDod = q.selectAny(sql_doc_z.rdDoc((int)currentTypeDoc, icd)); //q.sh(rdDod);

                ic = functionService.nextCod.codNext2(rdDod); icc = 1000 + ic; iccs = icc.ToString().Substring(1, 3);// h.m(h.az(ic, "=ic"));
                sicd = string.Concat(icd, (int)currentTypeDoc, iccs);
                icodd = Convert.ToInt32(sicd);
            }
            else
            {            //112161002

                if (currentTypeDocOP == ETALON.raw.typeDocOP.no)
                {
                    icodd = icd * 10000 + 1000 * (int)currentTypeDoc + 1; //h.m(h.az(icodd,"=icodd"));
                }
                else if (currentTypeDocOP == ETALON.raw.typeDocOP.ost)
                {
                    icodd = icd * 10000 + 1900; 
                }
                else if (currentTypeDocOP == ETALON.raw.typeDocOP.prihSklad)
                {
                    icodd = icd * 10000 + 1000 * (int)currentTypeDoc + 1; 
                }
            }
            object ocod123New = q.selectScalar(string.Concat( "select max(cod123)+1 as cod123 from ",sirRdZ ,";"));

            string sql_dml_add = sql_doc_z.ADD_rd
                (
                Convert.ToInt32(ocod123New),
                icodd,
                corgo,
                vv.rd.dateSmena, //functionService.DATECOD.get_Now_YearMonthDate
                vv.o_l_0_cod,  //q.tc_int(param.o_l_0)
                "0"
                );
           //h.m(sql_dml_add);
            q.UpdateData(sql_dml_add);
            
            loadDoc(currentTypeDocOP);

        }
        private int intDoc
        {
            get 
            {
                
                if (currentTypeDoc == ETALON.raw.typeDoc.NKR ) { return 4000; }
                else if (currentTypeDoc == ETALON.raw.typeDoc.SFP ) { return 2000; }
                else if (currentTypeDoc == ETALON.raw.typeDoc.NKRS) { return 3000; }
                else { return 1000; }
            }
        }

        public void delDoc()
        {
            string s = tool.listView3.SelectedItems[0].Tag.ToString(); //h.m(s);
            int cod123 = functionService.tagWork.readTAGi(s, (int)raw.typeTagRd.cod123_3); // h.m(cod123);
            q.UpdateData(sql_doc_z.DEL_rd(cod123));
            tool.listView3.SelectedItems[0].Remove();

        }
        public void editDoc()
        {
            string s = tool.listView3.SelectedItems[0].Tag.ToString();// h.m(s);
            int cod123 = functionService.tagWork.readTAGi(s, (int)raw.typeTagRd.cod123_3);
            //  h.m(cod123 );
            editParam_SELECT_sirRd(cod123);

        }
        public void editDocTd()
        {
            string s = tool.listView2.SelectedItems[0].Tag.ToString(); //h.m(s);
            int cod123 = functionService.tagWork.readTAGi(s, (int)raw.typeTagTd.cod123_5);

             // h.m(cod123 );
            editParam_SELECT_sirTd(cod123);

        }
        public void editParam_SELECT_sirTd(int cod123o)
        {
            //r[0]-name, r[1]-kol, r[2]-kol2 , r[3]-pr, r[5]-codd, r[6]-cod123 
            string tagSelect = "";
            /*
name
kol
kol2
pr
--sd
codd
cod123
             
             
             
             ТОРТ фруктовый ПЕРСИК (35);1;690;0;203031001;3304  */

            ListViewItem[] vi = new ListViewItem[6];
            #region name-index-tag
            vi[0] = new ListViewItem("Наименование");
            vi[1] = new ListViewItem("Кол");
            vi[2] = new ListViewItem("Кол2");
            vi[3] = new ListViewItem("Цена");
            vi[4] = new ListViewItem("КодД");
            vi[5] = new ListViewItem("Код123");

            vi[0].ImageIndex = 1;
            vi[1].ImageIndex = 3;
            vi[2].ImageIndex = 3;
            vi[3].ImageIndex = 3;
            vi[4].ImageIndex = 3;
            vi[5].ImageIndex = 3;

            if (vv.list_sourse == "list_tehsir_z")
                vi[0].Tag = string.Concat((int)workType.selectSirTehn, "; name");
            else
                vi[0].Tag = string.Concat((int)workType.selectProdZeh, "; name");

            vi[1].Tag = string.Concat((int)workType.selectKol_siTd , "; kol");
            vi[2].Tag = string.Concat((int)workType.selectKol2_sirTd , "; kol2");
            vi[3].Tag = string.Concat((int)workType.selectPr_sirTd , "; pr");
            vi[4].Tag = string.Concat((int)workType.non , "; codd");
            vi[5].Tag = string.Concat((int)workType.non, "; cod123");

#endregion
           
            //functionService.tagWork.readTAG 
            //vi[0].SubItems.Add(q.tk_readTagRd(param.sir_tag_rd_24, ETALON.raw.typeTagRd.nd_1));
            vv.editTd.name_cod = q.tk_readTagTd( param.sir_td_tag_29, ETALON.raw.typeTagTd.name_0);
            vv.editTd.ct = nc.readCod(vv.editTd.name_cod);
            vv.editTd.currentCod123 = q.tk_readTagTd(param.sir_td_tag_29, ETALON.raw.typeTagTd.cod123_5);
            vv.editTd.kol = q.tk_readTagTd(param.sir_td_tag_29, ETALON.raw.typeTagTd.kol_1);
            vv.editTd.kol2 = q.tk_readTagTd(param.sir_td_tag_29, ETALON.raw.typeTagTd.kol2_2);
            vv.editTd.pr = q.tk_readTagTd(param.sir_td_tag_29, ETALON.raw.typeTagTd.pr_3);
            vv.editTd.codd = q.tk_readTagTd(param.sir_td_tag_29, ETALON.raw.typeTagTd.codd_4);

            vi[0].SubItems.Add(vv.editTd.name_cod);
            vi[1].SubItems.Add(vv.editTd.kol);
            vi[2].SubItems.Add(vv.editTd.kol2 );
            vi[3].SubItems.Add(vv.editTd.pr );
            vi[4].SubItems.Add(vv.editTd.codd );
            vi[5].SubItems.Add(vv.editTd.currentCod123);

            string s24 = q.tk(param.sir_td_tag_29);

            vi[0].Font = new Font("Tahoma", 24);
            vi[1].Font = new Font("Tahoma", 24);
            vi[2].Font = new Font("Tahoma", 24);
            vi[3].Font = new Font("Tahoma", 24);
            vi[4].Font = new Font("Tahoma", 24);
            vi[5].Font = new Font("Tahoma", 24);

            FormListParam f = new FormListParam(vi); f.ShowDialog();

            if (f.IsOk)
            {
                string s1 = f.listView1.Items[0].SubItems[1].Text;
                /*
name
kol
kol2
pr
--sd
codd
cod123*/
                string sql_Update = string.Concat("UPDATE ", shema, ".", sirTdZ , 
                    " SET ct = ", vv.editTd.ct,
                    ", kol = ", vv.editTd.kol.Replace(",", "."), //da.date_to_cod_str( vv.editParam_date_25)
                    ", kol2 = ", vv.editTd.kol2.Replace(",", "."),
                    ", pr = ", vv.editTd.pr.Replace(",",".") ,
                    " where cod123 = ", cod123o, ";");

                //if (vv.o_l_0_cod == 4) h.m(h.az(sql_Update, " only for programmer"));

                q.UpdateData(sql_Update);
               // object o = q.selectScalar(string.Concat("SELECT listSourse FROM sir_listorg WHERE cod=", vv.sir_org_23_CodInt, ";"));
                //vv.list_sourse = o.ToString();
                loadDocTd();
            }
        }
        public void editParam_SELECT_sirRd(int cod123o)
        {

            string tagSelect = "";
            /*codo    dd     codsotr     nd*/

            ListViewItem[] vi = new ListViewItem[3];

            vi[0] = new ListViewItem("№Док");
            vi[1] = new ListViewItem("Дата");
            vi[2] = new ListViewItem("Наименование (код)");

            vi[0].ImageIndex = 1;
            vi[1].ImageIndex = 11;
            vi[2].ImageIndex = 3;

            vi[0].Tag = string.Concat((int)workType.text, "; nd");
            vi[1].Tag = string.Concat((int)workType.date, "; dd");
            vi[2].Tag = string.Concat((int)workType.selectOrg, "; codo");


            //functionService.tagWork.readTAG 
            vi[0].SubItems.Add(q.tk_readTagRd(param.sir_tag_rd_24, ETALON.raw.typeTagRd.nd_1));
            string s24 = q.tk(param.sir_tag_rd_24);

            //h.m(h.az(1, s24 ));
            vv.editParam_date_25 =
                functionService.tagWork.readTAG(s24, (int)raw.typeTagRd.dd_4);
            // h.m(vv.editParam_date_25);


            vi[1].SubItems.Add(functionService.DATECOD.cod_to_date(Convert.ToInt32(vv.editParam_date_25)));
            // h.m(h.az(Convert.ToInt32(vv.editParam_date_25), 2));
            vi[2].SubItems.Add(functionService.tagWork.readTAG(q.tk(param.sir_tag_rd_24), (int)raw.typeTagRd.name_cod_corg_2));

            vi[0].Font = new Font("Tahoma", 24);
            vi[1].Font = new Font("Tahoma", 24);
            vi[2].Font = new Font("Tahoma", 24);

            vv.sir_org_23 = q.tk((int)param.sir_org_23);
            FormListParam f = new FormListParam(vi); f.ShowDialog();

            if (f.IsOk)
            {
                string s1 = f.listView1.Items[0].SubItems[1].Text;

                string sql_Update = string.Concat("UPDATE ",shema ,".",sirRdZ," SET nd = '", s1,
                    "', dd = ", o_editParam_date_25_toCodInt(vv.editParam_date_25), //da.date_to_cod_str( vv.editParam_date_25)
                    ", codo = ",  nc.readCod( vv.sir_org_23),
                    " where cod123 = ", cod123o, ";");
                //h.m(h.aa(sql_Update, "  vv.editParam_date_25=", vv.editParam_date_25));
                //if (vv.o_l_0_cod == 4) h.m(h.az(sql_Update, " only for programmer"));

                q.UpdateData(sql_Update);
                object o = q.selectScalar(string.Concat("SELECT listSourse FROM sir_listorg WHERE cod=", vv.sir_org_23_CodInt, ";"));
                vv.list_sourse = o.ToString();
                loadDoc();
            }
        }
        public object o_editParam_date_25_toCodInt(object sv)
        {
            object o = "";
            if (sv.ToString().Contains("."))
            {
                o = da.date_to_cod_str(sv); //h.m(o);
            }
            else
            {
                o = sv;// h.m(o);
            }

            return o;
        }


        public void toolStripMenuItem8Click_2()
        {
            object iCodd = q.tk_readTagRd(param.sir_tag_rd_24, ETALON.raw.typeTagRd.codd_5);
            functionService.prm_city plpc = new functionService.prm_city();
            //--------------------------------------
            td = q.selectAny(sql_doc_z.td_nakl(iCodd));
            //--------------------------------------
            //GRID.FormGRID gr = new GRID.FormGRID(td);
            //gr.ShowDialog();
            Report rep = new Report("Nakladnaya", td, string.Concat("Накладная № ", tgw.readTAG(plpc.tk((int)param.sir_tag_rd_24), 0), "/", tgw.readTAG(plpc.tk((int)param.sir_tag_rd_24), 1), " от ", da.cod_to_date(tgw.readTAG(plpc.tk((int)param.sir_tag_rd_24), 4)), "\n\n"), string.Concat("\n\n                       Итого наименований - ", td.Compute("Count(name)", "name <> '0'"), " \n\n                       Отпустил _____________________________________________________ \n\n                       Получил _____________________________________________________"), "50;300;100;100;100;0;0", "№пп;Наименование;Кол-во1;Кол-во2;Итог Кол-во;col;col");
            rep.ShowReport();

        }
        public void listView3_Select()
        {
            int ic = tool.listView3.SelectedItems.Count;
            if (ic > 0)
            {
                string stext = tool.listView3.SelectedItems[0].Text;
                string stag = tool.listView3.SelectedItems[0].Tag.ToString();
                tool.toolStripStatusLabel2.Text = stag;

               // h.m(h.aa(stext,stag));

                string scodo =
                 functionService.nameCod.readCod
                 (
                 functionService.tagWork.readTAG(stag, (int)raw.typeTagRd.name_cod_corg_2)
                 );
                object os = q.selectScalar(string.Concat("SELECT listSourse FROM sir_listorg WHERE cod = ", scodo, ";"));
                vv.list_sourse = os.ToString();
                string stag_doc = functionService.tagWork.readTAG(stag, (int)raw.typeTagRd.codd001_0);
                q.put(param.sir_current_doc_20, stag_doc);
                string stag_doc_cod123 = functionService.tagWork.readTAG(stag, (int)raw.typeTagRd.cod123_3); //h.m(stag_doc_cod123);
                q.put(param.sir_current_doc_cod123_21, stag_doc_cod123); q.put(param.sir_tag_rd_24, stag);
                setStatus(stext);
                loadDocTd();
                if (currentModeWAED != ETALON.raw.modeWAED.loadForReadOnly)
                {
                    setModeWAED(ETALON.raw.modeWAED.afterSelectRd);
                }
            }
        }
        public void setForeColorButtons(raw.typeDoc tdo, raw.typeDocOP dop)
        {

            tool.toolStripMenuItem2.ForeColor = Color.Gainsboro;
            tool.toolStripMenuItem4.ForeColor = Color.Gainsboro;
            tool.toolStripMenuItem5.ForeColor = Color.Gainsboro;
            tool.toolStripMenuItem6.ForeColor = Color.Gainsboro;
            if (tdo == ETALON.raw.typeDoc.NKP && dop == ETALON.raw.typeDocOP.no) { tool.toolStripMenuItem2.ForeColor = Color.MediumSeaGreen; }
            else if (tdo == ETALON.raw.typeDoc.NKP && dop == ETALON.raw.typeDocOP.ost) { tool.toolStripMenuItem4.ForeColor = Color.MediumSeaGreen; }
            else if (tdo == ETALON.raw.typeDoc.NKP && dop == ETALON.raw.typeDocOP.prihSklad) { tool.toolStripMenuItem5.ForeColor = Color.MediumSeaGreen; }
            else if (tdo == ETALON.raw.typeDoc.SFP) { tool.toolStripMenuItem4.ForeColor = Color.MediumSeaGreen; }
            else if (tdo == ETALON.raw.typeDoc.NKRS) { tool.toolStripMenuItem5.ForeColor = Color.MediumSeaGreen; }
            else if (tdo == ETALON.raw.typeDoc.NKR) { tool.toolStripMenuItem6.ForeColor = Color.Chocolate; }

        }
        public void setForeColorButtons(raw.typeDoc tdo)
        {
            
//toolStripMenuItem6
//toolStripMenuItem12
//toolStripMenuItem2
//toolStripMenuItem5
//toolStripMenuItem4
            tool.toolStripMenuItem6.ForeColor = Color.Gainsboro;
            tool.toolStripMenuItem12.ForeColor = Color.Gainsboro;
            tool.toolStripMenuItem2.ForeColor = Color.Gainsboro;
            tool.toolStripMenuItem5.ForeColor = Color.Gainsboro;
            tool.toolStripMenuItem4.ForeColor = Color.Gainsboro;
            if (tdo == ETALON.raw.typeDoc.NKP) 
            {
                tool.toolStripMenuItem4.ForeColor = Color.MediumSeaGreen;
                tool.toolStripMenuItem5.ForeColor = Color.MediumSeaGreen; 
            }
            else if (tdo == ETALON.raw.typeDoc.SFP) 
            { 
                tool.toolStripMenuItem2.ForeColor = Color.SteelBlue; 
            }
            else if (tdo == ETALON.raw.typeDoc.NKRS) 
            { tool.toolStripMenuItem12.ForeColor = Color.DarkOrange; }
            else if (tdo == ETALON.raw.typeDoc.NKR) { tool.toolStripMenuItem6.ForeColor = Color.Chocolate; }

        }
        public void funSetMode(raw.typeDoc tdo, string stxto, Color col)
        {
            currentTypeDoc = tdo; 
            q.put(param.sir_activTypeDoc_22, (int)tdo); 
            tool.toolStripStatusLabel3.Text = stxto;
            tool.toolStripStatusLabel3.BackColor = col;
            setForeColorButtons(tdo);vv.list_sourse= funSetListSourse(tdo);
            loadDoc(); 
        }
        public void funSetMode(raw.typeDoc tdo, raw.typeDocOP dop, string stxto, Color col)
        {
            currentTypeDoc = tdo; q.put(param.sir_activTypeDoc_22, (int)tdo);
            tool.toolStripStatusLabel3.Text = stxto; tool.toolStripStatusLabel3.BackColor = col;
            setForeColorButtons(tdo, dop); vv.list_sourse = funSetListSourse(tdo);
            loadDoc(dop);
        }
        
        public string funSetListSourse(raw.typeDoc tdo)
        {//list_tehsir_z
            string list_tehsir_z = "list_tehsir_z", list_sc = "list_sc", s = "";
            if (tdo == ETALON.raw.typeDoc.NKP)
            { s = list_tehsir_z; }
            else if (tdo == ETALON.raw.typeDoc.NKR)
            { s = list_sc; }
            else if (tdo == ETALON.raw.typeDoc.SFP)
            { s = list_sc; }
            else if (tdo == ETALON.raw.typeDoc.NKRS)
            { s = list_tehsir_z; }
            return s;
        }
        public void setModeTypeDoc(raw.typeDoc mo)
        {
            if (mo == ETALON.raw.typeDoc.NKP)
            { funSetMode(ETALON.raw.typeDoc.NKP, "Тип : Нк Приход", Color.MediumSeaGreen); }
            else if (mo == ETALON.raw.typeDoc.SFP) 
            { funSetMode(ETALON.raw.typeDoc.SFP, "Тип : Сф Приход", Color.SteelBlue); }
            else if (mo == ETALON.raw.typeDoc.NKRS) 
            { funSetMode(ETALON.raw.typeDoc.NKRS, "Тип : Сф Расход", Color.DarkOrange); }
            else if (mo == ETALON.raw.typeDoc.NKR)
            { funSetMode(ETALON.raw.typeDoc.NKR, "Тип : Нк Расход", Color.Chocolate); }
        }
        public void setModeTypeDoc(raw.typeDoc mo, raw.typeDocOP dop)
        {
            currentTypeDocOP = dop;
            if (mo == ETALON.raw.typeDoc.NKP && dop == ETALON.raw.typeDocOP.no )
            { funSetMode(ETALON.raw.typeDoc.NKP, dop, "Тип : Нк Приход", Color.SteelBlue); }
            else if (mo == ETALON.raw.typeDoc.NKP && dop == ETALON.raw.typeDocOP.ost )
            {
                if (q.tk(param.day_work_7).Substring(0, 2) == "01")
                {
                    funSetMode(ETALON.raw.typeDoc.NKP, dop, "Тип : Нк Остатки", Color.SteelBlue);
                }
                else { h.m("Режим начальных остатков возможен только в первом числе месяца"); }
            }
            else if (mo == ETALON.raw.typeDoc.NKP && dop == ETALON.raw.typeDocOP.prihSklad)
            { funSetMode(ETALON.raw.typeDoc.NKP, dop, "Тип : Нк Приход Склад", Color.SteelBlue); }
            else if (mo == ETALON.raw.typeDoc.SFP && dop == ETALON.raw.typeDocOP.no )
            { funSetMode(ETALON.raw.typeDoc.SFP, "Тип : Сф Приход", Color.SteelBlue); }
            else if (mo == ETALON.raw.typeDoc.NKRS && dop == ETALON.raw.typeDocOP.no)
            { funSetMode(ETALON.raw.typeDoc.NKRS, "Тип : Нк Расход Склад", Color.DarkOrange); }
            else if (mo == ETALON.raw.typeDoc.NKR && dop == ETALON.raw.typeDocOP.no)
            { funSetMode(ETALON.raw.typeDoc.NKR, "Тип : Нк Расход", Color.Chocolate); }
        }
        #region MODE
        public void setModeWAED(raw.modeWAED mo)
        {
            if (mo == ETALON.raw.modeWAED.load)
            {
                #region Enabled true false
                tool.toolStripMenuItem7.Enabled = false; //печать
                tool.toolStripButton3.Enabled = true;  //+
                tool.toolStripButton4.Enabled = false;   // удаление док
                tool.toolStripButton6.Enabled = false;  //редактир
                tool.toolStripButton1.Enabled = false;  //+ товар
                tool.toolStripButton2.Enabled = false;   //уд товар
                tool.toolStripButton5.Enabled = false;  // ред товар

                tool.toolStripMenuItem2.Enabled = true; //нк п
                tool.toolStripMenuItem4.Enabled = true;  //сф п
                tool.toolStripMenuItem5.Enabled = true; //сф р
                tool.toolStripMenuItem6.Enabled = true; //нк р

                tool.toolStripMenuItem3.Enabled = true;   //сервис
                #endregion
            }
            else if (mo == ETALON.raw.modeWAED.addRd)
            {
                #region Enabled true false
                tool.toolStripMenuItem7.Enabled = false; //печать
                tool.toolStripButton3.Enabled = true;  //+
                tool.toolStripButton4.Enabled = false;   // удаление док
                tool.toolStripButton6.Enabled = false;  //редактир
                tool.toolStripButton1.Enabled = false;  //+ товар
                tool.toolStripButton2.Enabled = false;   //уд товар
                tool.toolStripButton5.Enabled = false;  // ред товар

                tool.toolStripMenuItem2.Enabled = true; //нк п
                tool.toolStripMenuItem4.Enabled = true;  //сф п
                tool.toolStripMenuItem5.Enabled = true; //сф р
                tool.toolStripMenuItem6.Enabled = true; //нк р

                tool.toolStripMenuItem3.Enabled = true;   //сервис
                #endregion
            }
            else if (mo == ETALON.raw.modeWAED.addTd)
            {
                #region Enabled true false
                tool.toolStripMenuItem7.Enabled = false; //печать
                tool.toolStripButton3.Enabled = false;  //+
                tool.toolStripButton4.Enabled = false;   // удаление док
                tool.toolStripButton6.Enabled = false;  //редактир
                tool.toolStripButton1.Enabled = true;  //+ товар
                tool.toolStripButton2.Enabled = false;   //уд товар
                tool.toolStripButton5.Enabled = false;  // ред товар

                tool.toolStripMenuItem2.Enabled = false; //нк п
                tool.toolStripMenuItem4.Enabled = false;  //сф п
                tool.toolStripMenuItem5.Enabled = false; //сф р
                tool.toolStripMenuItem6.Enabled = false; //нк р

                tool.toolStripMenuItem3.Enabled = false;   //сервис
                #endregion
            }
            else if (mo == ETALON.raw.modeWAED.afterSelectRd)
            {
                #region Enabled true false
                tool.toolStripMenuItem7.Enabled = false; //печать
                tool.toolStripButton3.Enabled = true;  //+
                tool.toolStripButton4.Enabled = true;   // удаление док
                tool.toolStripButton6.Enabled = true;  //редактир
                tool.toolStripButton1.Enabled = true;  //+ товар
                tool.toolStripButton2.Enabled = false;   //уд товар
                tool.toolStripButton5.Enabled = false;  // ред товар
                tool.toolStripButton8.Enabled = true;

                tool.toolStripMenuItem2.Enabled = true; //нк п
                tool.toolStripMenuItem4.Enabled = true;  //сф п
                tool.toolStripMenuItem5.Enabled = true; //сф р
                tool.toolStripMenuItem6.Enabled = true; //нк р

                tool.toolStripMenuItem3.Enabled = true;   //сервис
                #endregion
            }
            else if (mo == ETALON.raw.modeWAED.afterSelectTd)
            {
                #region Enabled true false
                tool.toolStripMenuItem7.Enabled = false; //печать
                tool.toolStripButton3.Enabled = false;  //+
                tool.toolStripButton4.Enabled = false;   // удаление док
                tool.toolStripButton6.Enabled = false;  //редактир
                tool.toolStripButton1.Enabled = true;  //+ товар
                tool.toolStripButton2.Enabled = true;   //уд товар
                tool.toolStripButton5.Enabled = true;  // ред товар

                tool.toolStripMenuItem2.Enabled = false; //нк п
                tool.toolStripMenuItem4.Enabled = false;  //сф п
                tool.toolStripMenuItem5.Enabled = false; //сф р
                tool.toolStripMenuItem6.Enabled = false; //нк р

                tool.toolStripMenuItem3.Enabled = true;   //сервис
                #endregion
            }
            else if (mo == ETALON.raw.modeWAED.delRd)
            {
                #region Enabled true false
                tool.toolStripMenuItem7.Enabled = false; //печать
                tool.toolStripButton3.Enabled = true;  //+
                tool.toolStripButton4.Enabled = false;   // удаление док
                tool.toolStripButton6.Enabled = false;  //редактир
                tool.toolStripButton1.Enabled = false;  //+ товар
                tool.toolStripButton2.Enabled = false;   //уд товар
                tool.toolStripButton5.Enabled = false;  // ред товар

                tool.toolStripMenuItem2.Enabled = true; //нк п
                tool.toolStripMenuItem4.Enabled = true;  //сф п
                tool.toolStripMenuItem5.Enabled = true; //сф р
                tool.toolStripMenuItem6.Enabled = true; //нк р

                tool.toolStripMenuItem3.Enabled = true;   //сервис
                #endregion
            }
            else if (mo == ETALON.raw.modeWAED.delTd)
            {
                #region Enabled true false
                tool.toolStripMenuItem7.Enabled = false; //печать
                tool.toolStripButton3.Enabled = true;  //+
                tool.toolStripButton4.Enabled = false;   // удаление док
                tool.toolStripButton6.Enabled = false;  //редактир
                tool.toolStripButton1.Enabled = true;  //+ товар
                tool.toolStripButton2.Enabled = false;   //уд товар
                tool.toolStripButton5.Enabled = false;  // ред товар

                tool.toolStripMenuItem2.Enabled = false; //нк п
                tool.toolStripMenuItem4.Enabled = false;  //сф п
                tool.toolStripMenuItem5.Enabled = false; //сф р
                tool.toolStripMenuItem6.Enabled = false; //нк р

                tool.toolStripMenuItem3.Enabled = true;   //сервис
                #endregion
            }
            else if (mo == ETALON.raw.modeWAED.selectRd)
            {

            }
            else if (mo == ETALON.raw.modeWAED.selectTd)
            {

            }
            else if (mo == ETALON.raw.modeWAED.loadForReadOnly)
            {
                #region Enabled true false
                tool.toolStripMenuItem7.Enabled = true; //печать
                tool.toolStripButton3.Enabled = false;  //+
                tool.toolStripButton4.Enabled = false;   // удаление док
                tool.toolStripButton6.Enabled = false;  //редактир
                tool.toolStripButton1.Enabled = false;  //+ товар
                tool.toolStripButton2.Enabled = false;   //уд товар
                tool.toolStripButton5.Enabled = false;  // ред товар

                tool.toolStripMenuItem2.Enabled = false; //нк п
                tool.toolStripMenuItem4.Enabled = false;  //сф п
                tool.toolStripMenuItem5.Enabled = false; //сф р
                tool.toolStripMenuItem6.Enabled = false; //нк р

                tool.toolStripMenuItem3.Enabled = true;   //сервис
                //h.m("loadForReadOnly");
                #endregion
            }
            currentModeWAED = mo;

        }

        public void setStatus(string stxto)
        {
            tool.toolStripStatusLabel3.Text = stxto;
        }
        #endregion
       
    }
}

namespace ETALON
{
    namespace raw
    {
        enum modeWAED
        {
            load, selectRd, afterSelectRd, selectTd, afterSelectTd, delRd, delTd, addRd, addTd, loadForReadOnly
        }
        enum typeDoc {NKP = 1, SFP = 2, NKRS = 3, NKR = 4 }
        enum typeDocOP { ost=1900, prihSklad=1300, no=1000}

        /*SELECT right(codd,3)*1 as codd3, s.nd, name_cod(n.name, s.codo) as codo, s.cod123, s.dd, s.codd
FROM sir_rd s*/
        enum typeTagRd { codd001_0 = 0, nd_1 = 1, name_cod_corg_2 = 2, cod123_3 = 3, dd_4 = 4, codd_5 = 5 }


        /*
             * SELECT name_cod(n.name, ct) as name, kol, pr, kol*pr as sd ,codd, s.cod123 
             * FROM sir_td s left join listtov n on s.ct=n.cod 
             * where codd = coddo 
             * order by s.cod123;
             * 
             */
        enum typeTagTd { name_0 = 0, kol_1 = 1, kol2_2 = 2, pr_3 = 3, codd_4 = 4, cod123_5 = 5 }
        enum PLP_reports { wide_1_4_7_10__1 = 1, wide__2_3__5_6__8_9__11_12__2 = 2, height_3 = 3 }
    }

    public class Tool
    {
        //toolStripMenuItem6
        //toolStripMenuItem12
        //toolStripMenuItem2
        //toolStripMenuItem5
        //toolStripMenuItem4
        public ToolStripMenuItem toolStripMenuItem2;
        public ToolStripMenuItem toolStripMenuItem3;
        public ToolStripMenuItem toolStripMenuItem4;
        public ToolStripMenuItem toolStripMenuItem5;
        public ToolStripMenuItem toolStripMenuItem6;
        public ToolStripMenuItem toolStripMenuItem7;
        public ToolStripMenuItem toolStripMenuItem12;
        public ToolStripButton toolStripButton1;
        public ToolStripButton toolStripButton2;
        public ToolStripButton toolStripButton3;
        public ToolStripButton toolStripButton4;
        public ToolStripButton toolStripButton5;
        public ToolStripButton toolStripButton6;
        public ToolStripButton toolStripButton8;

        public ToolStripMenuItem toolStripMenuItem1;
        public ToolStripStatusLabel toolStripStatusLabel1, toolStripStatusLabel3, toolStripStatusLabel2;


        public ListView listView2, listView3;


        public Tool
            (
            ToolStripMenuItem toolStripMenuItem120,
                ToolStripMenuItem toolStripMenuItem20,
                ToolStripMenuItem   toolStripMenuItem30,
                ToolStripMenuItem   toolStripMenuItem40,
                ToolStripMenuItem   toolStripMenuItem50,
                ToolStripMenuItem   toolStripMenuItem60,
                ToolStripMenuItem   toolStripMenuItem70,
                ToolStripButton   toolStripButton10,
                ToolStripButton toolStripButton20,
                ToolStripButton  toolStripButton30,
                ToolStripButton toolStripButton40,
                ToolStripButton  toolStripButton50,
                ToolStripButton  toolStripButton60,
                 ToolStripButton toolStripButton80,

                ToolStripMenuItem toolStripMenuItem10,
                ToolStripStatusLabel  toolStripStatusLabel10,
                ToolStripStatusLabel  toolStripStatusLabel20,
                ToolStripStatusLabel  toolStripStatusLabel30,

                ListView  listView20, 
                ListView listView30
            )
        {
            toolStripMenuItem12 = toolStripMenuItem120;
            toolStripMenuItem2 = toolStripMenuItem20;
            toolStripMenuItem3 = toolStripMenuItem30;
            toolStripMenuItem4 = toolStripMenuItem40;
            toolStripMenuItem5 = toolStripMenuItem50;
            toolStripMenuItem6 = toolStripMenuItem60;
            toolStripMenuItem7 = toolStripMenuItem70;
            toolStripButton1 = toolStripButton10;
            toolStripButton2 = toolStripButton20;
            toolStripButton3 = toolStripButton30;
            toolStripButton4 = toolStripButton40;
            toolStripButton5 = toolStripButton50;
            toolStripButton6 = toolStripButton60;
            toolStripButton8 = toolStripButton80;


            toolStripMenuItem1 = toolStripMenuItem10;
            toolStripStatusLabel1 = toolStripStatusLabel10;
            toolStripStatusLabel2 = toolStripStatusLabel20;
            toolStripStatusLabel3 = toolStripStatusLabel30;


            listView2 = listView20; listView3 = listView30;

        }

       
    }
    public class sql_doc_z
    {
        //   addDoc(1, ETALON.raw.typeDoc.NKP);
        //
        const string t_rd = "sir_rd_z", t_td = "sir_td_z", city = "city";

        public static string rdDoc(object codd1234, object codDate10913)
        {
            string sql = string.Concat("call `", city , "`.`", t_rd  ,"_newDoc`(", codd1234, ",", codDate10913, ");"); return sql;
        }
        public static string rdDocType(int iTypeDoc, object codDate10913)
        {
            string sql = "";
            //const string t_rd = "sir_rd_z", t_td = "sir_td_z", city = "city";
            if (iTypeDoc == (int)raw.typeDoc.SFP )
            {
                sql = string.Concat("call `", city, "`.`",t_rd ,"_typeDocSf`(", iTypeDoc, ",", codDate10913, ");");
            }
            else
            {
                sql = string.Concat("call `", city, "`.`",t_rd ,"_typeDoc`(", iTypeDoc, ",", codDate10913, ");");
            }
            return sql;
        }
        public static string rdDocType(int iTypeDoc, int iTypeDocOP, object codDate10913)
        {
            string sql = "";
            if (iTypeDoc == (int)raw.typeDoc.SFP || iTypeDoc == (int)raw.typeDoc.NKRS)
            {
                sql = string.Concat("call `", city, "`.`", t_rd, "_typeDocSf`(", iTypeDoc, ",", codDate10913, ");");
            }
            else if (iTypeDoc == (int)raw.typeDoc.NKP && iTypeDocOP == (int)raw.typeDocOP.ost)
            {
                sql = string.Concat("call `", city, "`.`", t_rd, "_typeDocOP`(", iTypeDoc, ",", iTypeDocOP, ",", codDate10913, ");");
            }
            else if (iTypeDoc == (int)raw.typeDoc.NKP && iTypeDocOP == (int)raw.typeDocOP.prihSklad)
            {
                sql = string.Concat("call `", city, "`.`", t_rd, "_typeDocOP`(", iTypeDoc, ",", iTypeDocOP, ",", codDate10913, ");");
            }
            else if (iTypeDoc == (int)raw.typeDoc.NKP && iTypeDocOP == (int)raw.typeDocOP.no)
            {
                sql = string.Concat("call `", city, "`.`", t_rd, "_typeDoc`(", iTypeDoc, ",", codDate10913, ");");
            }
            else
            {
                sql = string.Concat("call `", city, "`.`", t_rd, "_typeDoc`(", iTypeDoc, ",", codDate10913, ");");
            }
            return sql;
        }
        public static string edit_td(int cod123, object kol, object kol2)
        {
            string sql = string.Concat("call `city`.`rz_update_td`( ", cod123, ",",
                kol.ToString().Replace(",","."), ", ",
                kol2.ToString().Replace(",","."), ")"); return sql;
        }
        public static string rd(int codDate10929o)
        {
            string sql = string.Concat("call `", city, "`.`select_", t_rd  ,"`(", codDate10929o, ");"); return sql;
        }
        public static string ADD_rd(int coddo, int codoo, int idd, int codsotro, string ndo)
        {
            string sql_dml =
            string.Concat("insert into ",t_rd,"(codd, codo, dd, codsotr, fpa,  nd)",
            "VALUES (", codoo, ", ", idd, ", ", codsotro, ", 0, '", ndo, "');");
            return sql_dml;
        }
        public static string ADD_rd(int cod123o, int coddo, int codoo, int idd, int codsotro, string ndo)
        {
            string sql_dml =
            string.Concat("insert into ", city, ".", t_rd, "(cod123, codd, codo, dd, codsotr, fpa,  nd)",
            "VALUES (", cod123o, ", ", coddo, ", ", codoo, ", ", idd, ", ", codsotro, ", 0, '", ndo, "');");
            return sql_dml;
        }
        public static string ADD_rd(object coddo, object codoo, object idd, object codsotro, object ndo)
        {
            string sql_dml =
            string.Concat("insert into ", t_rd, "(codd, codo, dd, codsotr, fpa,  nd)",
            "VALUES (", coddo, ",   ", codoo, ", ", idd, ", ", codsotro, ", 0, '", ndo, "');");
            return sql_dml;
        }
        public static string ADD_rd(object cod123o, object coddo, object codoo, object idd, object codsotro, object ndo, object coddSklado)
        {
            string sql_dml =
            string.Concat("insert into ", t_rd, "(cod123, codd, codo, dd, codsotr, fpa,  nd)",
            "VALUES (", cod123o, ",", coddo, ",   ", codoo, ", ", idd, ", ", codsotro, ", 0, '", ndo, "');");
            return sql_dml;
        }
        public static string ADD_sir_rd_sklad(object ndo, object ddo, object vdo, object corgo, object dp1o, object dp2o, object dp3o)
        {
            string sql_dml =
            string.Concat("insert into sir_rd_sklad(nd, dd, vd, corg, dp1,  dp2, dp3)",
            "VALUES (", ndo, ",   ", ddo, ", '", vdo, "', ", corgo, ", '", dp1o, "', '", dp2o, "', '", dp3o, "');");
            return sql_dml;
        }
        public static string ADD_rd(object coddo, object codoo, object idd, object codsotro, object ndo, object coddSklado)
        {
            string sql_dml =
            string.Concat("insert into ", t_rd, "(codd, codo, dd, codsotr, fpa,  nd)",
            "VALUES (", coddo, ",   ", codoo, ", ", idd, ", ", codsotro, ", 0, '", ndo, "', '", coddSklado, "');");
            return sql_dml;
        }
        public static string DEL_rd(int cod123o)
        {
            string sql_dml = string.Concat("delete from ", t_rd, " where cod123 = ", cod123o, ";"); return sql_dml;
        }
        public static string DEL_rd_ALL()
        {
            string sql_dml = string.Concat("delete from ", t_rd, ";"); return sql_dml;
        }
        public static string DEL_td_ALL()
        {
            string sql_dml = string.Concat("delete from ", t_td, ";"); return sql_dml;
        }
        public static string DEL_td(object cod123o)
        {
            string sql_dml = string.Concat("delete from ", t_td, " where cod123 = ", cod123o, ";"); return sql_dml;
        }
        public static string td_sum(object coddo)
        {
            string sql_dml = string.Concat("call `", city, "`.`sir_td_sum_z` (", coddo, ");");
            return sql_dml;
        }
        public static string td_count(object coddo)
        {
            string sql_dml = string.Concat("call `", city, "`.`sir_td_sum_z` (", coddo, ");");
            return sql_dml;
        }
        public static string td(object coddo)
        {
            //        const string t_rd = "sir_rd_z", t_td = "sir_td_z", city = "city";
            string s900 = coddo.ToString().Substring(6, 3); string sql_dml="";
            if (s900 == "900")
            {
                /*SELECT name_cod(
    n.name
    , ct) as name, kol, kol2, pr, kol*kol2*pr as sd ,codd, s.cod123
FROM sir_td_z s*/
                sql_dml = string.Concat("call `", city, "`.`sir_td_z900` (", coddo, ",'", vv.list_sourse, "');");
            }
            else
            {
                sql_dml = string.Concat("call `", city, "`.`sir_td_z` (", coddo, ",'", vv.list_sourse, "');");
            }
                return sql_dml;
        }
        public static string td_nakl(object coddo)
        {
            string sql_dml = string.Concat("call `", city, "`.`",t_td,"_nakl` (", coddo, ");");
            return sql_dml;
        }
        public static string ADD_td(object cto, object pro, object kolo, object coddo)
        {
            string sql_dml =
            string.Concat("insert into ", t_td, "(ct, pr, kol, numcod, codd, posm)",
            "VALUES (", cto, ",   ", pro.ToString().Replace(',', '.'), ", ",
                                     kolo.ToString().Replace(',', '.'), ", 0,", coddo, ", 0 );");
            return sql_dml;
        }
        public static string ADD_td(object cod123o, object cto, object pro, object kolo, object kolo2, object coddo)
        {
            string sql_dml =
            string.Concat("insert into ", t_td, "(cod123, ct, pr, kol, kol2, numcod, codd, posm)",
            "VALUES (", cod123o, ",", cto, ",   ", pro.ToString().Replace(',', '.'), ", ",
                                     kolo.ToString().Replace(',', '.'), ", ",
                                     kolo2.ToString().Replace(',', '.'),
                                     ", 0,", coddo, ", 0 );");
            return sql_dml;
        }


    }
    public class sql_doc
    {
        //   addDoc(1, ETALON.raw.typeDoc.NKP);
        //
        public static string rdDoc(object codd1234, object codDate10913)
        {
            string sql = string.Concat("call `city`.`sir_rd_newDoc`(", codd1234, ",", codDate10913, ");"); return sql;
        }
        public static string rdDocType(int iTypeDoc, object codDate10913)
        {
            string sql = "";
            if (iTypeDoc == (int)raw.typeDoc.SFP || iTypeDoc == (int)raw.typeDoc.NKRS)
            {
                sql = string.Concat("call `city`.`sir_rd_typeDocSf`(", iTypeDoc, ",", codDate10913, ");");
            }
            else
            {
                sql = string.Concat("call `city`.`sir_rd_typeDoc`(", iTypeDoc, ",", codDate10913, ");");
            }
            return sql;
        }
        public static string rd(int codDate10929o)
        {
            string sql = string.Concat("call `city`.`select_sirRd`(", codDate10929o, ");"); return sql;
        }
        public static string ADD_rd(int coddo, int codoo, int idd, int codsotro, string ndo)
        {
            string sql_dml =
            string.Concat("insert into sir_rd(codd, codo, dd, codsotr, fpa,  nd)",
            "VALUES (", codoo, ", ", idd, ", ", codsotro, ", 0, '", ndo, "');");
            return sql_dml;
        }
        public static string ADD_rd(int cod123o, int coddo, int codoo, int idd, int codsotro, string ndo)
        {
            string sql_dml =
            string.Concat("insert into city.sir_rd(cod123, codd, codo, dd, codsotr, fpa,  nd)",
            "VALUES (", cod123o, ", ", coddo, ", ", codoo, ", ", idd, ", ", codsotro, ", 0, '", ndo, "');");
            return sql_dml;
        }
        public static string ADD_rd(object coddo, object codoo, object idd, object codsotro, object ndo)
        {
            string sql_dml =
            string.Concat("insert into sir_rd(codd, codo, dd, codsotr, fpa,  nd)",
            "VALUES (", coddo, ",   ", codoo, ", ", idd, ", ", codsotro, ", 0, '", ndo, "');");
            return sql_dml;
        }
        public static string ADD_rd(object cod123o, object coddo, object codoo, object idd, object codsotro, object ndo, object coddSklado)
        {
            string sql_dml =
            string.Concat("insert into sir_rd(cod123, codd, codo, dd, codsotr, fpa,  nd)",
            "VALUES (", cod123o, ",", coddo, ",   ", codoo, ", ", idd, ", ", codsotro, ", 0, '", ndo, "');");
            return sql_dml;
        }
        public static string ADD_sir_rd_sklad(object ndo, object ddo, object vdo, object corgo, object dp1o, object dp2o, object dp3o)
        {
            string sql_dml =
            string.Concat("insert into sir_rd_sklad(nd, dd, vd, corg, dp1,  dp2, dp3)",
            "VALUES (", ndo, ",   ", ddo, ", '", vdo, "', ", corgo, ", '", dp1o, "', '", dp2o, "', '", dp3o, "');");
            return sql_dml;
        }
        public static string ADD_rd(object coddo, object codoo, object idd, object codsotro, object ndo, object coddSklado)
        {
            string sql_dml =
            string.Concat("insert into sir_rd(codd, codo, dd, codsotr, fpa,  nd)",
            "VALUES (", coddo, ",   ", codoo, ", ", idd, ", ", codsotro, ", 0, '", ndo, "', '", coddSklado, "');");
            return sql_dml;
        }
        public static string DEL_rd(int cod123o)
        {
            string sql_dml = string.Concat("delete from sir_rd where cod123 = ", cod123o, ";"); return sql_dml;
        }
        public static string DEL_rd_ALL()
        {
            string sql_dml = string.Concat("delete from sir_rd;"); return sql_dml;
        }
        public static string DEL_td_ALL()
        {
            string sql_dml = string.Concat("delete from sir_td;"); return sql_dml;
        }
        public static string DEL_td(object cod123o)
        {
            string sql_dml = string.Concat("delete from sir_td where cod123 = ", cod123o, ";"); return sql_dml;
        }
        public static string td_sum(object coddo)
        {
            string sql_dml = string.Concat("call `city`.`sir_td_sum` (", coddo, ");");
            return sql_dml;
        }
        public static string td_count(object coddo)
        {
            string sql_dml = string.Concat("call `city`.`sir_td_sum` (", coddo, ");");
            return sql_dml;
        }
        public static string td(object coddo)
        {
            string sql_dml = string.Concat("call `city`.`sir_td` (", coddo, ",'", vv.list_sourse, "');");
            return sql_dml;
        }
        public static string td_nakl(object coddo)
        {
            string sql_dml = string.Concat("call `city`.`sir_td_nakl` (", coddo, ");");
            return sql_dml;
        }
        public static string ADD_td(object cto, object pro, object kolo, object coddo)
        {
            string sql_dml =
            string.Concat("insert into sir_td(ct, pr, kol, numcod, codd, posm)",
            "VALUES (", cto, ",   ", pro.ToString().Replace(',', '.'), ", ",
                                     kolo.ToString().Replace(',', '.'), ", 0,", coddo, ", 0 );");
            return sql_dml;
        }
        public static string ADD_td(object cod123o, object cto, object pro, object kolo, object kolo2, object coddo)
        {
            string sql_dml =
            string.Concat("insert into sir_td(cod123, ct, pr, kol, kol2, numcod, codd, posm)",
            "VALUES (", cod123o, ",", cto, ",   ", pro.ToString().Replace(',', '.'), ", ",
                                     kolo.ToString().Replace(',', '.'), ", ",
                                     kolo2.ToString().Replace(',', '.'),
                                     ", 0,", coddo, ", 0 );");
            return sql_dml;
        }


    }
}